package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import java.util.Collection; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblCTDTChuyenNganh;
import com.lb.jwitter.service.TblCTDTChuyenNganhService;
import com.lb.jwitter.service.TblCTDTKhoa;
import com.lb.jwitter.service.TblCTDTKhoaService;

import com.lb.jwitter.service.TblCTDTHeDaoTao;
import com.lb.jwitter.service.TblCTDTHeDaoTaoService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblCTDTChuyenNganhUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private String ten; 
    public void setTen(String ten) {
       this.ten = ten;
 }

    public String getTen() {
       return ten;
 }

    private String ma; 
    public void setMa(String ma) {
       this.ma = ma;
 }

    public String getMa() {
       return ma;
 }

    private String maNganhChung; 
    public void setMaNganhChung(String maNganhChung) {
       this.maNganhChung = maNganhChung;
 }

    public String getMaNganhChung() {
       return maNganhChung;
 }

    private int khoaId; 
    public void setKhoaId(int khoaId) {
       this.khoaId = khoaId;
 }

    public int getKhoaId() {
       return khoaId;
 }

    private int heDaoTaoId; 
    public void setHeDaoTaoId(int heDaoTaoId) {
       this.heDaoTaoId = heDaoTaoId;
 }

    public int getHeDaoTaoId() {
       return heDaoTaoId;
 }

    private TblCTDTChuyenNganh tblCTDTChuyenNganh; 
    public void setTblCTDTChuyenNganh (TblCTDTChuyenNganh tblCTDTChuyenNganh) {
        this.tblCTDTChuyenNganh = tblCTDTChuyenNganh;
 }

    private Collection<TblCTDTChuyenNganh> tblCTDTChuyenNganhs; 
    public void setTblCTDTChuyenNganhs(Collection<TblCTDTChuyenNganh> tblCTDTChuyenNganhs) {
        this.tblCTDTChuyenNganhs = tblCTDTChuyenNganhs; 
      } 

    private TblCTDTChuyenNganhService tblCTDTChuyenNganhService; 

    private TblCTDTKhoaService tblCTDTKhoaService; 

    private TblCTDTHeDaoTaoService tblCTDTHeDaoTaoService; 

	private int preUpdate(Message msg, TblCTDTChuyenNganh obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblCTDTChuyenNganh obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_CTDT_ChuyenNganh", "sua")){ 
        return "noprivilege"; 
    }
        tblCTDTChuyenNganhService = (TblCTDTChuyenNganhService) context.getBean("tbl_CTDT_ChuyenNganhClient"); 
        tblCTDTKhoaService = (TblCTDTKhoaService) context.getBean("tbl_CTDT_KhoaClient"); 

        tblCTDTHeDaoTaoService = (TblCTDTHeDaoTaoService) context.getBean("tbl_CTDT_HeDaoTaoClient"); 

        msg = new Message(); 
        tblCTDTChuyenNganh = tblCTDTChuyenNganhService.gettblCTDTChuyenNganh(new Long(id)); 
        tblCTDTChuyenNganh.setTen(ten); 
        tblCTDTChuyenNganh.setMa(ma); 
        tblCTDTChuyenNganh.setMaNganhChung(maNganhChung); 
        tblCTDTChuyenNganh.setKhoaId(tblCTDTKhoaService.gettblCTDTKhoa(new Long(khoaId))); 
        tblCTDTChuyenNganh.setHeDaoTaoId(tblCTDTHeDaoTaoService.gettblCTDTHeDaoTao(new Long(heDaoTaoId))); 
        preUpdate(msg,tblCTDTChuyenNganh); 
       if (msg.isPreMessage_b()) 
       { 
           tblCTDTChuyenNganhService.updatetblCTDTChuyenNganh(tblCTDTChuyenNganh); 
           postUpdate(msg, tblCTDTChuyenNganh); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_CTDT_ChuyenNganh Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
